package com.kxr.literetrofit.network;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Path;
import retrofit2.http.QueryMap;
import retrofit2.http.Url;

/**
 * Created by kongxr on 2019/2/28.
 * 应用全局HOST
 */
public interface ApiService {

    boolean isAlServer = true;

    String HOST = "https://127.0.0.1:8090"; //主机host test
    String BASE_URL = isAlServer ? HOST + "/oauth/api/" : "oauth/api/";//默认服务器地址

    @GET("{url}")
    Observable<ResponseBody> executeGet(
            @Path(value = "url", encoded = true) String url,
            @QueryMap Map<String, String> maps);

    @FormUrlEncoded
    @POST("{url}")
    Observable<ResponseBody> executePost(
            @Path(value = "url", encoded = true) String url,
            @FieldMap Map<String, String> maps);


//    // TODO: 2019/3/12 testing
//    @POST("{url}")
//    <T>Observable<XindunResponse2> executePostList(
//            @Path("url") String url,
//            @Body List<T> params);

    @POST("{url}")
    Observable<ResponseBody> executePostBody(
            @Path(value = "url", encoded = true) String url,
            @Body RequestBody body);

    //独立url，不受全局host地址影响
    @POST()
    Observable<ResponseBody> executePostBodyWithUrl(
            @Url String url,
            @Body RequestBody body);

    @Multipart
    @POST("{url}")
    Observable<ResponseBody> uploadFile(
            @Path(value = "url", encoded = true) String url,
            @PartMap Map<String, RequestBody> params,
            @Part MultipartBody.Part fileBody);

    @Multipart
    @POST("{url}")
    Observable<ResponseBody> totalUrlUploadFile(
            @Url String url,
            @PartMap Map<String, RequestBody> params,
            @Part MultipartBody.Part fileBody);

    @POST("{url}")
    Observable<ResponseBody> uploadFiles(
            @Path(value = "url", encoded = true) String url,
//            @PartMap Map<String, RequestBody> params);
            @Body RequestBody fileBody);

    @Multipart
    @POST("{url}")
    Observable<ResponseBody> downFile(
            @Path(value = "url", encoded = true) String url,
            @PartMap Map<String, RequestBody> params);

    @Multipart
    @POST("{url}")
    Observable<ResponseBody> totalUrlDownFile(
            @Url String url,
            @PartMap Map<String, RequestBody> params);
}